﻿namespace WinwiseARDrone.API
{
    public class HandleDroneInput
    {
        internal bool Launch
        {
            get;
            set;
        }
        internal bool Land
        {
            get;
            set;
        }
        internal bool Emergency
        {
            get;
            set;
        }

        /// <summary>
        /// Controle la montée/descente
        /// </summary>
        public float Gaz
        {
            get;
            set;
        }

        /// <summary>
        /// Controle l'inclinaison avant/arrière
        /// </summary>
        public float Pitch
        {
            get;
            set;
        }

        /// <summary>
        /// Controle l'inclinaison latérale
        /// </summary>
        public float Roll
        {
            get;
            set;
        }

        /// <summary>
        /// Controle la rotation gauche/droite
        /// </summary>
        public float Yaw
        {
            get;
            set;
        }

        public bool Hovering
        {
            get;
            set;
        }

        internal int OpenInput()
        {
            return 0;
        }

        internal int UpdateInput()
        {
            DroneController.ardrone_tool_set_ui_pad_select(0);

            if (this.Launch)
            {
                DroneController.ardrone_tool_set_ui_pad_start(1);
                this.Launch = false;
            }

            if (this.Land)
            {
                DroneController.ardrone_tool_set_ui_pad_start(0);
                this.Land = false;
            }

            if (this.Emergency)
            {
                DroneController.ardrone_tool_set_ui_pad_start(0);
                DroneController.ardrone_tool_set_ui_pad_select(1);
                this.Emergency = false;
            }

            this.Hovering = this.Roll == 0 && this.Pitch == 0;

            DroneController.ardrone_at_set_progress_cmd(this.Hovering ? 0 : 1, this.Roll, this.Pitch, this.Gaz, this.Yaw);

            return 0;
        }

        internal int CloseInput()
        {
            return 0;
        }
    }
}
